/**
 * Generali Solutions d'assurances - Tous droits réservés &copy; 2007 - 2010
 */
package fr.generali.accueilclient.utils.code.error;

import java.math.BigInteger;
import java.util.ResourceBundle;

/**
 * @author Holmes Kelly
 */
public enum ControleIBANCodeError {

    /**
     * 
     */
    CODE_ERROR_00(0, "erreur.services.rce.controle.iban.00"),

    /**
     * 
     */
    CODE_ERROR_04(4, "erreur.services.rce.controle.iban.04"),

    /**
     * 
     */
    CODE_ERROR_05(5, "erreur.services.rce.controle.iban.05"),

    /**
     * 
     */
    CODE_ERROR_07(7, "erreur.services.rce.controle.iban.07"),

    /**
     * 
     */
    CODE_ERROR_08(8, "erreur.services.rce.controle.iban.08"),

    /**
     * 
     */
    CODE_ERROR_09(9, "erreur.services.rce.controle.iban.09"),

    /**
     * 
     */
    CODE_ERROR_13(13, "erreur.services.rce.controle.iban.13"),

    /**
     * 
     */
    CODE_ERROR_14(14, "erreur.services.rce.controle.iban.14"),

    /**
     * 
     */
    CODE_ERROR_19(19, "erreur.services.rce.controle.iban.19"),

    /**
     * 
     */
    CODE_ERROR_20(20, "erreur.services.rce.controle.iban.20"),

    /**
     * 
     */
    CODE_ERROR_22(22, "erreur.services.rce.controle.iban.22"),

    /**
     * 
     */
    CODE_ERROR_25(25, "erreur.services.rce.controle.iban.25"),

    /**
     * 
     */
    CODE_ERROR_NON_DEFINI(99, "erreur.services.rce.controle.iban.99");

    /**
     * code error
     */
    private Integer code;

    /**
     * message error
     */
    private String message;

    /**
     * @param code code error
     * @param message message error
     */
    private ControleIBANCodeError(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * @return the code
     */
    public Integer getCode() {
        return code;
    }

    /**
     * @return the message
     */
    public String getMessage() {
        return message;
    }

    /**
     * @param cle cle message error services
     * @return message
     */
    public static String getMessageErrorService(String cle) {

        ResourceBundle bundle = ResourceBundle.getBundle("fr.generali.accueilclient.erreur-services-business");

        return bundle.getString(cle);
    }

    /**
     * @param cle cle message error services
     * @return message
     */
    public static String getMessageErrorServiceParCode(BigInteger codeError) {

        for (ControleIBANCodeError ibanCodeError : values()) {

            if (BigInteger.valueOf(ibanCodeError.code.longValue()).equals(codeError)) {

                return getMessageErrorService(ibanCodeError.message);
            }
        }

        return getMessageErrorService(CODE_ERROR_NON_DEFINI.message);
    }
    
    /**
     * 
     * @param codeError codeError
     * @return message
     */
    public static String getMessageErrorServiceParCode(ControleIBANCodeError codeError) {

        for (ControleIBANCodeError ibanCodeError : values()) {

            if (ibanCodeError.equals(codeError)) {

                return getMessageErrorService(ibanCodeError.message);
            }
        }

        return getMessageErrorService(CODE_ERROR_NON_DEFINI.message);
    }

    /**
     * @param codeError code error
     * @return ControleIBANCodeError
     */
    public static ControleIBANCodeError getControleIBAN(BigInteger codeError) {

        ControleIBANCodeError controleIBANCodeError = CODE_ERROR_NON_DEFINI;

        for (ControleIBANCodeError ibanCodeError : values()) {

            if (BigInteger.valueOf(ibanCodeError.code.longValue()).equals(codeError)) {

                return ibanCodeError;
            }
        }

        return controleIBANCodeError;
    }

}
